/*
 * 类名称:ProductRelateShopController.java
 * 包名称:com.platform.controller
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2019-08-28 14:42:41        lipengjun     初版做成
 *
 * Copyright (c) 2019-2019 微同科技
 */
package com.platform.controller;

import com.platform.annotation.SysLog;
import com.platform.entity.ProductRelateShopEntity;
import com.platform.service.ProductRelateShopService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 商铺产品关系表Controller
 *
 * @author lipengjun
 * @date 2019-08-28 14:42:41
 */
@RestController
@RequestMapping("productrelateshop")
public class ProductRelateShopController extends AbstractController {
    @Autowired
    private ProductRelateShopService productRelateShopService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("productrelateshop:list")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<ProductRelateShopEntity> list = productRelateShopService.queryAll(params);

        return R.ok().put("list", list);
    }

    /**
     * 分页查询商铺产品关系表
     *
     * @param params 查询参数
     * @return R
     */
    @GetMapping("/list")
    @RequiresPermissions("productrelateshop:list")
    public R list(@RequestParam Map<String, Object> params) {

        //查询列表数据
        Query query = new Query(params);

        List<ProductRelateShopEntity> menuList = productRelateShopService.queryList(query);

        int total = productRelateShopService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(menuList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return R
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("productrelateshop:info")
    public R info(@PathVariable("id") Integer id) {
        ProductRelateShopEntity productRelateShop = productRelateShopService.selectById(id);

        return R.ok().put("productRelateShop", productRelateShop);
    }

    /**
     * 新增商铺产品关系表
     *
     * @param productRelateShop productRelateShop
     * @return R
     */
    @SysLog("新增商铺产品关系表")
    @RequestMapping("/save")
    @RequiresPermissions("productrelateshop:save")
    public R save(@RequestBody ProductRelateShopEntity productRelateShop) {

        productRelateShopService.add(productRelateShop);

        return R.ok();
    }

    /**
     * 修改商铺产品关系表
     *
     * @param productRelateShop productRelateShop
     * @return R
     */
    @SysLog("修改商铺产品关系表")
    @RequestMapping("/update")
    @RequiresPermissions("productrelateshop:update")
    public R update(@RequestBody ProductRelateShopEntity productRelateShop) {

        productRelateShopService.update(productRelateShop);

        return R.ok();
    }

    /**
     * 根据主键删除商铺产品关系表
     *
     * @param ids ids
     * @return R
     */
    @SysLog("删除商铺产品关系表")
    @RequestMapping("/delete")
    @RequiresPermissions("productrelateshop:delete")
    public R delete(@RequestBody Integer[] ids) {
        productRelateShopService.deleteBatch(ids);
        return R.ok();
    }
}
